@extends('admin.master')
<script src="/js/admin/deviceList.js"></script>
@section('title', '设备列表')
@section('header')
@parent
	
@stop
@section('firstItem')
@parent
				<span>设备列表</span>
				<input class="a_indexbg" type="hidden" value="devicelist" />
				
@stop
@section('searchList')
@parent
				<a class="aaa">搜索</a>
				<div>
					<input class="deviceCodeBox" type="text" value="{{ $condition or '' }}" placeholder="输入用户名或设备编号" />
				</div>
				<div>
					<p>设备状态：</p>
					<span class="deviceCheckBox">{{ $status or '全部' }}</span>
					<div class="deviceCheckDropBox">
						<a>全部</a>
						<a>检修</a>
						<a>缺水</a>
						<a>停机</a>
						<a>漏水</a>
						<a>欠费</a>
					</div>
				</div>
@stop
@section('dataTables')
@parent
			<div class="tableBox">
				<table class="dataTable dataTables" cellspacing="0" cellpadding="0">
					<thead>
						<tr>
							<td>序号</td>
							<td>设备编号</td>
							<td>用户名</td>
							<td style="width:5%">剩余流量(L)</td>
							<td>剩余天数(D)</td>
							<td>制水量(L)</td>
							<td>滤芯1</td>
							<td>滤芯2</td>
							<td>滤芯3</td>
							<td>滤芯4</td>
							<!-- <td>滤芯5</td> -->
							<td>原水TDS</td>
							<td>净水TDS</td>
							<td>水机状态</td>
							<td style="width:7%">记录时间</td>
							<td>经销商</td>
							<td>水机用户</td>
							<td>停机操作</td>
							@if($user->hasAnyAccess('superadmin') || $user->hasAnyAccess('finance'))
							<td>充值</td>
							@endif
							<td>历史记录</td>
						</tr>
					</thead>
					<tbody>

						@for($i=0, $deviceCount=count($device_list); $i<$deviceCount; $i++)

							@if($device_list[$i]->dec_status == 2)
						<tr class="lessWaterBg">
							@elseif($device_list[$i]->dec_status == 4)
						<tr class="serviceBg">
							@elseif($device_list[$i]->dec_status == 8)
						<tr class="leakageBg">
							@elseif($device_list[$i]->dec_status == 9)
						<tr class="shutDownBg">
							@else
						<tr >
							@endif
							<td><input type="hidden" value="{{ $device_list[$i]->device_id }}" />{{ $i+1 }}</td>
							<td class="deviceCodeCell devicecodeVal">{{ $device_list[$i]->device->code }}</td>
							<td class="userListCell">{{ $device_list[$i]->device->installInfo->customer_name or '尚未录入' }}</td>
							<td class="residueFluxCell">{{ $device_list[$i]->residual_flow or '/' }}</td>
							<td class="residueDaysCell">{{ $device_list[$i]->time_limit or '/' }}</td>
							<td>{{ $device_list[$i]->amount_water or '/' }}</td>
							<td class="filterWidth">{{ $device_list[$i]->filter1 }}%</td>
							<td class="filterWidth">{{ $device_list[$i]->filter2 }}%</td>
							<td class="filterWidth">{{ $device_list[$i]->filter3 }}%</td>
							<td class="filterWidth">{{ $device_list[$i]->filter4 }}%</td>
							<!-- <td class="filterWidth">{{ $device_list[$i]->filter5 }}%</td> -->
							<td>{{ $device_list[$i]->TDS1 }}</td>
							@if($device_list[$i]->TDS2 >= 45)
							<td class="warningBg">
							@else
							<td>
							@endif
							{{ $device_list[$i]->TDS2 }}</td>
							<td>{{ $device_list[$i]->device_status_description }}</td>
							<td>{{ $device_list[$i]->created_at }}</td>
							<td>{{ $device_list[$i]->device->installInfo->dealer or '尚未录入' }}</td>
							@if($userCount = count($device_list[$i]->device->userInfos))
							<td class="userList">
								@for($j=0; $j<$userCount; $j++)
									@if($j == $userCount - 1)
									{{ $device_list[$i]->device->userInfos[$j]->name }}
									@else
									{{ $device_list[$i]->device->userInfos[$j]->name }}、
									@endif
								@endfor
							</td>
							@else
							<td></td>
							@endif
							<td>
							@if($device_list[$i]->device->status !=2)
							<a class="switch">停机</a>
							@else
							<a class="switch">开启</a>
							@endif
							</td>
							@if($user->hasAnyAccess('superadmin') || $user->hasAnyAccess('finance'))
							<td class="positionParent">
								<input type="hidden" value="{{ $device_list[$i]->device->installInfo->installation_address or '尚未录入' }}" />
								<a class="payFluxBtn">充值</a>
								<div class="modeBox">
									<a class="meterageMode">计量模式</a>
									<a class="packageMode">套餐模式</a>
								</div>
							</td>
							@endif
							<td ><a href="/admin/device/history?device_id={{ $device_list[$i]->device_id }}">查看</a></td>
						</tr>
						@endfor
					</tbody>
				</table>
			</div>
@stop
@section('page_num')
<ul class="pagination pagination-lg">
	<?php
	$queryParam = [];
	$queryParam = empty($condition)? $queryParam: array_merge($queryParam, ['condition' => $condition]);
	$queryParam = empty($status)? $queryParam: array_merge($queryParam, ['status' => $status]);  ?>
	{!! $device_list->appends($queryParam)->render() !!}
</ul>
@stop
@section('infor_promit')
@parent
	<!-- 充值编辑框 -->
	<div class="payFlux meterageM" >
		<div class="displayBox p_relative">
			<div>
				<p><span>设备编号:</span><span class="getDeviceCode"></span></p>
				<p><span>剩余流量(L):</span><span class="getSurplusFlux"></span></p>
			</div>
			<div>
				<p><span>用户名:</span><span class="getUserList"></span></p>
				<p><span>剩余天数(D):</span><span class="getSurplusDays"></span></p>
			</div>
			<div>
				<p><span>安装地址:</span><span class="getAddress"></span></p>
			</div>
			<input type="hidden" class="fluxPrice" value="{{ $price }}" /><!--获取流量单价-->
			<p><textarea class="textareaBox Add-ons_txt" placeholder="备注信息："></textarea></p>
			<div class="payBox">充值金额(元)：<input class="payBoxInput" type="text" value="" placeholder="输入正整数" oninput="myFunction1()"/><label class="required">*</label>
				<div class="moneyNumDrop">
					<a>20</a>
					<a>50</a>
					<a>100</a>
					<a>200</a>
				</div>
			</div>
			<div class="payBox">充值流量(升)：<span class="fluxNumBox" style="margin-left: 20px;"></span></div>
			<label class="labelBox payMoneyLabelBox"></label>
		</div>
		<div class="btnBox" >
			<a class="noBtn deviceChargeNoBtn">取消</a>
			<a class="okBtn">确定</a>
		</div>
	</div>

	<div class="payFlux packageM" >
		<div class="displayBox p_relative">
			<div>
				<p><span>设备编号:</span><span class="getDeviceCode">2477163</span></p>
				<p><span>剩余流量(L):</span><span class="getSurplusFlux"></span></p>
			</div>
			<div>
				<p><span>用户名:</span><span class="getUserList"></span></p>
				<p><span>剩余天数(D):</span><span class="getSurplusDays"></span></p>
			</div>
			<div>
				<p><span>安装地址  :</span><span class="getAddress"></span></p>
			</div>
			<p><textarea class="textareaBox Add-ons_txt" placeholder="备注信息："></textarea></p>
			<div class="payBox">充值天数(天)：<input class="payBoxInput" type="text" value="" placeholder="输入正整数" oninput="myFunction2()"/><label class="required">*</label>
				<div class="moneyNumDrop">
					<a>20</a>
					<a>50</a>
					<a>100</a>
					<a>200</a>
				</div>
			</div>
			<label class="labelBox payMoneyLabelBox"></label>
		</div>
		<div class="btnBox" >
			<a class="noBtn deviceChargeNoBtn">取消</a>
			<a class="okBtn">确定</a>
		</div>
	</div>
	<!-- 开启关闭弹框 -->
	<div class="switchBox">
		<div style="font-weight: bold;">
			确定<span>关闭</span>设备
			<span class="getDeviceCode"></span>
		</div>
		<label class="labelBox switchLabelBox"></label>
		<div class="btnBox">
			<a class="noSwitch">取消</a>
			<a class="okSwitch">确定</a>
		</div>
	</div>
	<script>
		var reg =/^[0-9]*$/;
		function myFunction1(){
			if(!reg.test($(".meterageM .payBoxInput").val())){
				$(".meterageM .payMoneyLabelBox").html("请输入正整数！");
				$(".meterageM .fluxNumBox").html(0);
			}else if($(".meterageM .payBoxInput").val()==0){
				$(".meterageM .payMoneyLabelBox").html("请输入正整数！");
				$(".meterageM .fluxNumBox").html(0);
			}else{
				$(".meterageM .payMoneyLabelBox").html("");
				$(".meterageM .fluxNumBox").html(Math.round($(".meterageM .payBoxInput").val()/$(".meterageM .fluxPrice").val()));
			}
		}
		function myFunction2(){
			if(!reg.test($(".packageM .payBoxInput").val())){
				$(".packageM .payMoneyLabelBox").html("请输入正整数！");
			}else if($(".packageM .payBoxInput").val()==0){
				$(".packageM .payMoneyLabelBox").html("请输入正整数！");
			}else{
				$(".packageM .payMoneyLabelBox").html("");
			}
		}
	</script>
@stop